package com.dmcloud.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * Created by xiaodao
 * date: 2020/3/30
 */
@Configuration
public class DataBaseConfig {






    @Bean
    @ConfigurationProperties( "spring.datasource")
    public DataSource dataSource(){
        HikariDataSource hikariDataSource = new HikariDataSource();
        System.err.println("==============init hikariDataSource");
        return hikariDataSource;
    }

    /**
     * seata的代理数据源
     * @param dataSource
     * @return
     */
//    @Primary
//    @Bean("dataSourceProxy")
//    public DataSourceProxy dataSourceProxy(DataSource dataSource){
//        return new DataSourceProxy(dataSource);
//    }
//
//    @Bean
//    public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//        sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
//                .getResources("classpath:/mapper/**/*Mapper.xml"));
//        org.apache.ibatis.session.Configuration configuration = new MybatisConfiguration();
//        configuration.setMapUnderscoreToCamelCase(true);
//        sqlSessionFactoryBean.setConfiguration(configuration);
//        sqlSessionFactoryBean.setDataSource(dataSourceProxy);
//        sqlSessionFactoryBean.setTypeAliasesPackage("com.dmcloud.**.entity");
//        return sqlSessionFactoryBean.getObject();
//    }
//    @Bean
//    public GlobalTransactionScanner globalTransactionScanner() {
//        return new GlobalTransactionScanner("dm-price", "my_test_tx_group");
//    }

}
